﻿namespace MobileTrack.Web.Tests.ViewModels
{
    using System;
    using System.Globalization;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using MobileTrack.Core.Model;
    using MobileTrack.Web.ViewModels;

    [TestClass]
    public class AbonoViewModelFixture
    {
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ShouldThrowIfAbonoIsNull()
        {
            new AbonoViewModel(null);
        }

        [TestMethod]
        public void ShouldSetPropertiesIfAbonoIsNotNull()
        {
            var today = DateTime.Today;
            var marca = new Marca { Id = 2, Nombre = "Marca2", Codigo = 20 };
            var abono = new Abono { Id = 1, Descripcion = "Abono1", FechaInicio = today, FechaFin = today.AddDays(1), Precio = 200, MarcaId = 2, Operador = marca };
            abono.Ventas.Add(new Venta { Id = 1, AbonoId = 1, CelularId = 1, SeguimientoId = 1, Activado = true });

            var abonoVm = new AbonoViewModel(abono);

            Assert.AreEqual(1, abonoVm.Id);
            Assert.AreEqual("Abono1", abonoVm.Descripcion);
            Assert.AreEqual(200, abonoVm.Precio);
            Assert.AreEqual(2, abonoVm.OperadorId);
            Assert.AreEqual("Marca2", abonoVm.Operador);
            Assert.AreEqual(1, abonoVm.CantVentas);
            Assert.AreEqual(today.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture), abonoVm.Inicio);
            Assert.AreEqual(today.AddDays(1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture), abonoVm.Fin);
        }
    }
}
